﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotSpatial.Topology;

namespace HAGISV2
{
    /// <summary>
    /// 网格相关数据计算使用此类
    /// </summary>
    public class GetNeededGridInfo
    {
        #region 公共方法

        /// <summary>
        /// 将无效区数据格式转换为int三维数组,Z Y X
        /// </summary>
        /// <param name="hyGrid"></param>
        /// <param name="boundary"></param>
        /// <returns></returns>
        public static int[, ,] TranslateList2DTo3D(HyGrid hyGrid,List<int[,]> boundary)
        {
            int[, ,] b;
            if (boundary == null || boundary.Count <= 0)
            {
                b = new int[hyGrid.LayersCount, hyGrid.RowsCount, hyGrid.ColsCount];
                for (int k = 0; k < hyGrid.LayersCount; k++)
                {
                    for (int j = 0; j < hyGrid.RowsCount; j++)
                    {
                        for (int i = 0; i < hyGrid.ColsCount; i++)
                        {
                            b[k, j, i] = 1;
                        }
                    }
                }
            }
            else
            {
                b = new int[boundary.Count, boundary[0].GetLength(0), boundary[0].GetLength(1)];
                for (int k = 0; k < boundary.Count; k++)
                {
                    for (int j = 0; j < boundary[0].GetLength(0); j++)
                    {
                        for (int i = 0; i < boundary[0].GetLength(1); i++)
                        {
                            b[k, j, i] = boundary[k][j, i];
                        }
                    }
                }
            }

            return b;
        }

        /// <summary>
        /// 获取当前网格视图单元格中心点坐标
        /// </summary>
        /// <param name="polygons"></param>
        /// <returns></returns>
        public static List<DotSpatial.Topology.Point> ComputeCentroidForLayerCells(List<DotSpatial.Topology.Polygon> polygons)
        {
            List<DotSpatial.Topology.Point> centroids = new List<DotSpatial.Topology.Point>();
            foreach (DotSpatial.Topology.Polygon item in polygons)
            {
                centroids.Add((DotSpatial.Topology.Point)item.Centroid);
            }

            return centroids;
        }



        # endregion

    }
}
